/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package objects;

import graphic.Color;
import graphic.Graphic;

/**
 *
 * @author Marcin
 */
public class Cube {
    public Color color;
    public float size=0;
    public float pos[] = new float[3];
    
    private Triangle[] t = new Triangle[12];

    public void draw(){
        if(size==0) return;
        Graphic.e.setColor(color);
        for(int i=0;i<12;++i)
            Graphic.e.drawTTrans(t[i],pos[0],pos[1],pos[2]);
    }
    
    public void resize(float size){
        this.size=size;
        gen();
    }
    
    public void move(float x,float y,float z){
        pos[0]=x;
        pos[1]=y;
        pos[2]=z;
    }
    
    public void set(float x,float y,float z,float size,Color c){
        pos[0]=x;
        pos[1]=y;
        pos[2]=z;
        color=c;
        this.size=size;
        gen();
    }    
    
    public void gen(){
        float hsize=size/2;
        t[0]=new Triangle( +hsize,-hsize,+hsize,
                           +hsize,+hsize,+hsize,                          
                           -hsize,+hsize,+hsize);
        t[1]=new Triangle( +hsize,-hsize,+hsize,
                           -hsize,+hsize,+hsize,
                           -hsize,-hsize,+hsize);
        
        
        t[2]=new Triangle( -hsize,+hsize,-hsize,
                           -hsize,-hsize,-hsize,
                           -hsize,+hsize,+hsize);
        t[3]=new Triangle( -hsize,-hsize,+hsize,
                           -hsize,+hsize,+hsize,
                           -hsize,-hsize,-hsize);
        
        
        t[4]=new Triangle( +hsize,+hsize,-hsize,
                           +hsize,-hsize,-hsize,
                           -hsize,+hsize,-hsize);
        t[5]=new Triangle( -hsize,-hsize,-hsize,
                           -hsize,+hsize,-hsize,
                           +hsize,-hsize,-hsize);
        
        t[6]=new Triangle( +hsize,+hsize,-hsize,
                           +hsize,+hsize,+hsize,
                           +hsize,-hsize,-hsize);
        t[7]=new Triangle( +hsize,-hsize,+hsize,
                           +hsize,-hsize,-hsize,
                           +hsize,+hsize,+hsize);
        
        t[8]=new Triangle( +hsize,+hsize,+hsize,
                           +hsize,+hsize,-hsize,
                           -hsize,+hsize,-hsize);
        t[9]=new Triangle( +hsize,+hsize,+hsize,
                           -hsize,+hsize,-hsize,
                           -hsize,+hsize,+hsize);
        
        t[10]=new Triangle( +hsize,-hsize,+hsize,
                            -hsize,-hsize,-hsize,
                            +hsize,-hsize,-hsize);
        t[11]=new Triangle( -hsize,-hsize,+hsize,
                            -hsize,-hsize,-hsize,
                            +hsize,-hsize,+hsize);
        
        for(int i=0;i<12;++i)
            t[i].calcNormal();
        
    }
}
